/**
 * 显示消息提示框
 * @param content 提示的标题
 */
export function toast(content) {
	uni.showToast({
		icon: 'none',
		title: content
	})
}

/**
 * 显示模态弹窗
 * @param content 提示的标题
 */
export function showConfirm(content,title) {
	return new Promise((resolve, reject) => {
		uni.showModal({
			title: title || '提示',
			content: content,
			cancelText: '取消',
			confirmText: '确定',
			success: function(res) {
				resolve(res)
			}
		})
	})
}

/**
 * 参数处理
 * @param params 参数
 */
export function tansParams(params) {
	let result = ''
	for (const propName of Object.keys(params)) {
		const value = params[propName]
		var part = encodeURIComponent(propName) + "="
		if (value !== null && value !== "" && typeof(value) !== "undefined") {
			if (typeof value === 'object') {
				for (const key of Object.keys(value)) {
					if (value[key] !== null && value[key] !== "" && typeof(value[key]) !== 'undefined') {
						let params = propName + '[' + key + ']'
						var subPart = encodeURIComponent(params) + "="
						result += subPart + encodeURIComponent(value[key]) + "&"
					}
				}
			} else {
				result += part + encodeURIComponent(value) + "&"
			}
		}
	}
	return result
}

/**
 * 判断当前时间是否在某时间段内
 * @beginDateStr beginDateStr 开始时间
 * @endDateStr endDateStr 结束时间
 */
export function isDuringDate(beginDateStr, endDateStr) {
	const formatBeginDateStr = beginDateStr.replace(/-/g, '/') //所有的- 都替换成/（IOS兼容处理）
	const formatEndDateStr = endDateStr.replace(/-/g, '/') //所有的- 都替换成/（IOS兼容处理）
	const curDate = new Date() // 当前时间
	const beginDate = new Date(Date.parse(formatBeginDateStr))
	const endDate = new Date(Date.parse(formatEndDateStr))
	if (curDate.getTime() >= beginDate.getTime() && curDate.getTime() <= endDate.getTime()) {
		return true
	}
	return false
}
export function checkAuditTime(beginTime, endTime) {
	let nowDate = new Date();
	let beginDate = new Date(nowDate);
	let endDate = new Date(nowDate);
	let beginIndex = beginTime.lastIndexOf("\:");
	let beginHour = beginTime.substring(0, beginIndex);
	let beginMinue = beginTime.substring(beginIndex + 1, beginTime.length);
	beginDate.setHours(beginHour, beginMinue, 0, 0);
	let endIndex = endTime.lastIndexOf("\:");
	let endHour = endTime.substring(0, endIndex);
	let endMinue = endTime.substring(endIndex + 1, endTime.length);
	endDate.setHours(endHour, endMinue, 0, 0);
	return nowDate.getTime() - beginDate.getTime() >= 0 && nowDate.getTime() <= endDate.getTime();
}
// 服务费电费拆分字符串
export function feeSplitVal(keyStr, strVal) {
	let strVals = strVal
	let keySplitArray = strVals.split(keyStr)
	let keySplitStrVal = keySplitArray[1]
	let strValArray = keySplitStrVal.split(',')
	let strValArraylg = strValArray.length
	let electricityServeAmtList = []
	for (let i = 0; i < strValArraylg; i++) {
		let obj = {}
		let item = strValArray[i]
		const timeSlot = item.substr(0, item.lastIndexOf(':'))
		const electricityPrice = item.substr(item.lastIndexOf(':') + 1)
		obj['timeSlot'] = timeSlot
		if (keyStr === '电费:') {
			obj['electricityPrice'] = electricityPrice
		} else {
			obj['serveicePrice'] = electricityPrice
		}
		electricityServeAmtList.push(obj)
	}
	console.log(electricityServeAmtList, 'electricityServeAmtList')
	return electricityServeAmtList
}

//获取以前时间
export function getPreviousDate(numOfDays) {
	var date = new Date();
	date.setDate(date.getDate() - numOfDays);
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var day = date.getDate();
	return year + "-" + month + "-" + day + ' ' + '00:00:00';
}

export function fungetCurrentTime() {
	//获取当前时间并打印
	var _this = this;
	let yy = new Date().getFullYear();
	let mm = new Date().getMonth() + 1;
	let dd = new Date().getDate();
	let hh = new Date().getHours();
	let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
	let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
	return yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
}

export function GetDateTime(dayNum) {
	var dateDay = new Date();
	dateDay.setDate(dateDay.getDate() + dayNum) //获取dayNum天后的日期
	console.log(dateDay);
	var y = dateDay.getFullYear();
	var m = (dateDay.getMonth() + 1) < 10 ? "0" + (dateDay.getMonth() + 1) : (dateDay.getMonth() +
	1); //获取当前月份的日期，不足10补0
	var d = dateDay.getDate() < 10 ? "0" + dateDay.getDate() : dateDay.getDate(); //获取当前几号，不足10补0
	return y + "-" + m + "-" + d;
}